#ifndef unigame_Stage_h
#define unigame_Stage_h

#include <vector>
#include "config/Def.h"

namespace unigame
{
	enum StageFlag
	{
		E_RENDER_LIST_CHANGE_SF = 1,
		E_RENDER_ORDER_CHANGE_SF = 1 << 1,
	};

	class GameObject;
	class Camera;
	class Display;
	class Stage
	{
	public:
		~Stage();

		void init();

		void clearStage();

		void addToStage(GameObject* obj);
		void removeFromStage(int32u index);
		void removeFromStage(GameObject* obj);

		void update();

		void render();

		static Stage* instance()
		{
			if(s_instance == 0)
			{
				s_instance = uni_new Stage();
			}
			return s_instance;
		}

		static void destroy()
		{
			uni_delete(s_instance);
		}

		std::vector<GameObject*>& getObjList()
		{
			return m_gameObjectList;
		}

		GameObject* isInStage(GameObject* go);

		void addCamera();

		int32u addDisplay();
		void removeDisplay(int32u disId);
		Display* getDisplay(int32u disId);

		void onResizeScreen();

		static void setFlag(int32u flag)
		{
			s_flag |= flag;
		}

		static void clearFlag(int32u flag)
		{
			s_flag &= ~flag;
		}

		static bool getFlag(int32u flag)
		{
			return (s_flag & flag) > 0;
		}

	private:
		Stage(){}
		Stage(const Stage& s);
		Stage& operator =(const Stage& s);
		void removeCamera(GameObject* obj);

	private:
		std::vector<GameObject*> m_gameObjectList;
		std::vector<Camera*> m_cameraList;
		std::vector<Display*> m_displays;

		static Stage* s_instance;
		static int32u s_flag;
	};
}

#endif